local jsrg_feiyang = fk.CreateSkill {
  name = "jsrg_feiyang",
}

jsrg_feiyang:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
        player.phase == Player.Judge and
        #player:getCardIds(Player.Hand) >= 2 and
        #player:getCardIds(Player.Judge) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askToDiscard(player,
      { min_num = 2, max_num = 2, include_equip = false, skill_name = self.name, 
      cancelable = true, pattern = ".", prompt = "#m_feiyang-invoke", skip = true })
    if #cards == 2 then
      event:setCostData(self,cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), self.name, player, player)
    local jcards = player:getCardIds("j")
    if #jcards == 0 then return end
    local card = #jcards == 1 and jcards[1] or room:askForCardChosen(player, player, "j", self.name)
    room:throwCard({ card }, self.name, player, player)
  end
})

return jsrg_feiyang
